﻿Imports Mysoft.Map.Data
Imports System.Data


Partial Public Class Cwjk_SelectFeeItem
    Inherits Mysoft.Map.Application.Security.AppPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Data_Bind()
            '设置级数
            Dim strLevelHtml As String = ""
            Dim i As Int32
            For i = 1 To 2
                strLevelHtml = strLevelHtml & "<a href='javascript:showLevel(" & i + 1 & ")' style='color:white;text-decoration: none' >&nbsp;" & i & "&nbsp;</a>"
            Next
            sHtml.Value = strLevelHtml
        End If

    End Sub
    Private Sub Data_Bind()
        Dim dtTemp, dtFeeItem As DataTable
        Dim strSQL, strIsUsedScopeRepeat, strParentCode, strCwztGUID, strUsedScopeList, strOperTypeGUID As String
        Dim i As Integer = 0
        strIsUsedScopeRepeat = Request.QueryString("IsUsedScopeRepeat")
        strParentCode = Request.QueryString("ParentCode")
        strCwztGUID = Request.QueryString("CwztGUID")
        strOperTypeGUID = Request.QueryString("OperTypeGUID")
        Me.txtSelectUsedScope.Text = Request.QueryString("SelectUsedScope")
        If strOperTypeGUID Is Nothing Or strOperTypeGUID = "" Then
            strOperTypeGUID = "00000000-0000-0000-0000-000000000000"
        End If

        If strIsUsedScopeRepeat = "True" Then
            strSQL = "SELECT ParamValue,ParamCode,ParamGUID,IfEnd  FROM myBizParamOption WHERE ParamName = 's_FeeItem' AND ScopeGUID = '" & Session("BUGUID") & "' ORDER BY ParamCode"
        Else
            dtFeeItem = MyDB.GetDataTable("SELECT UsedScope FROM p_CwjkOperType WHERE IsDisable=0 AND CwztGUID = '" & strCwztGUID & "' AND HierarchyCode  LIKE '" & strParentCode & ".%' AND OperTypeGUID <> '" & strOperTypeGUID & "'")
            If dtFeeItem.Rows.Count > 0 Then
                strUsedScopeList = ""
                For i = 0 To dtFeeItem.Rows.Count - 1
                    strUsedScopeList &= dtFeeItem.Rows(i).Item("UsedScope").ToString() & "，"
                Next
                strUsedScopeList = strUsedScopeList.Replace("，", "','").Trim("，")
                If strUsedScopeList = "" Then
                    strSQL = "SELECT ParamValue,ParamCode,ParamGUID,IfEnd FROM myBizParamOption WHERE ParamName = 's_FeeItem' AND ScopeGUID = '" & Session("BUGUID") & "' ORDER BY ParamCode"
                Else
                    strUsedScopeList = "'" & strUsedScopeList & "'"
                    strSQL = "SELECT DISTINCT parent.ParamValue ,parent.ParamCode,parent.ParamGUID,parent.IfEnd FROM " & _
                            " ( SELECT ParamValue,ParamCode,ParamGUID,IfEnd  FROM myBizParamOption WHERE ParamName = 's_FeeItem' AND ScopeGUID = '" & Session("BUGUID") & "') AS Parent" & _
                            " INNER JOIN ( SELECT ParamCode FROM myBizParamOption WHERE ParamName = 's_FeeItem' AND IfEnd=1 AND ScopeGUID = '" & Session("BUGUID") & "' AND ParamValue NOT IN (" & strUsedScopeList & ") ) AS FeeItem " & _
                            " ON FeeItem.ParamCode + '.' like Parent.ParamCode +'.%' ORDER BY parent.ParamCode "
                End If
            Else
                strSQL = "SELECT ParamValue,ParamCode,ParamGUID,IfEnd  FROM myBizParamOption WHERE ParamName = 's_FeeItem' AND ScopeGUID = '" & Session("BUGUID") & "' ORDER BY ParamCode"
            End If
        End If

        dtTemp = MyDB.GetDataTable(strSQL)

        '自定义控件绑定数据
        repItem.BindMode = 1                                          '绑定模式：0 -- SQL 语句绑定，1 -- DataTable 绑定
        repItem.DataTable = dtTemp
        repItem.DataBind()                                            '绑定数据

    End Sub
End Class